package com.color.admin.files.controller;

import com.color.admin.common.core.base.BaseController;
import com.color.admin.common.core.result.ResultData;
import com.color.admin.files.service.FilesService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author HaiQiu
 * @date 2022/1/6
 */
@Tag(name = "files-controller",description = "本地文件服务管理")
@RestController
@RequestMapping("files/serve")
public class FilesController extends BaseController {

    @Autowired
    private FilesService filesService;

    @Operation(summary = "本地文件上传",description = "文件本地上传到服务器，上传文件请使用form表单提交文件")
    @PostMapping("/upload")
    public ResultData upload(MultipartFile multipartFile, String folder){
        return decide(filesService.upload(multipartFile,folder));
    }

    @Operation(summary = "公共文件上传",description = "公共文件上传到服务器，上传文件请使用form表单提交文件")
    @PostMapping("/common/upload")
    public ResultData commonUpload(@Parameter(description = "文件上传表单名") @RequestParam("file")
                                               MultipartFile multipartFile){
        return decide("上传成功",filesService.commonUpload(multipartFile));
    }
}
